package com.mars.pay.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mars.pay.entity.PaymentLog;
import com.mars.pay.mapper.PaymentLogMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * 支付日志服务
 *
 * @author Mars
 */
@Slf4j
@Service
public class PaymentLogService extends ServiceImpl<PaymentLogMapper, PaymentLog> implements IService<PaymentLog> {

    /**
     * 记录支付日志
     *
     * @param orderNo         订单号
     * @param thirdOrderNo    第三方订单号
     * @param paymentType     支付方式
     * @param operationType   操作类型
     * @param requestParams   请求参数
     * @param responseResult  响应结果
     * @param success         是否成功
     * @param remark          备注
     */
    public void recordLog(String orderNo, String thirdOrderNo, String paymentType,
                          String operationType, String requestParams, String responseResult,
                          Integer success, String remark) {
        PaymentLog log = new PaymentLog();
        log.setOrderNo(orderNo);
        log.setThirdOrderNo(thirdOrderNo);
        log.setPaymentType(paymentType);
        log.setOperationType(operationType);
        log.setRequestParams(requestParams);
        log.setResponseResult(responseResult);
        log.setSuccess(success);
        log.setCreateTime(LocalDateTime.now());
        log.setRemark(remark);

        save(log);
    }
}

